package ui
{
	import Base.Loader.SWFLoader;
	
	import Common.GameDefine;
	import Common.GameResManager;
	
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class uiBase
	{
		public var uiMc:Object = null;
		public var path:String = "";
		public var name:String = "";
		public var movie:uiMovie;
		
		public var isVisible:Boolean = false;
		
		
		public function uiBase()
		{
			
		}
		
			
		public function resize():void
		{
			
		}
		
		
		public function onInit( loader:SWFLoader ):void
		{
			var clas:Class = loader.getClass( name );
			uiMc = new clas();
			uiMc.name = name;
			uiMc.visible = isVisible;
			
			movie = new uiMovie();
			movie.init( MovieClip( uiMc ) );
			movie.startTimer();
			
			GameUIManager.instance.addLevel1UI( uiMc );
			
			resize();
		}
		
		
		public function update( delay:Number ):void
		{
			if ( movie )
			{
				movie.update( delay );
			}
		}
		
		
		public function visible( b:Boolean ):void
		{
			isVisible = b;
			
			if ( b )
			{
				if ( !uiMc )
				{
					GameResManager.instance.load( GameDefine.PATHUI + path , onInit );
					return;
				}
				else
				{
					if ( uiMc.visible )
					{
						return;
					}
					
					uiMc.visible = true;
					
					movie.startTimer();
				}
			}
			else
			{
				if ( uiMc )
				{
					uiMc.visible = false;
				}
				
			}
		}
		
		
	}
	
}